<?php

// declare callbacks

function MyFunction ($function) {
	if ($function != 'func1') return false;
	echo '<p>MyFunction called for lookup function <strong>' . $function . '</strong></p>';
	return './functions/' . $function . '.php';
}

$MyAnonymFunction = create_function ('$function', '
	if ($function != "func2") return false;
	echo "<p>MyAnonymFunction called for lookup function <strong>" . $function . "</strong></p>";
	return "./functions/" . $function . ".php";
');

class MyStaticClass {
	public static function MyStaticMethod ($function) {
		if ($function != 'func3') return false;
		echo "<p>MyStaticClass::MyStaticMethod called for lookup function <strong>" . $function . "</strong></p>";
		return './functions/' . $function . '.php';
	}
}

class MyClass {
	public function MyMethod ($function) {
		if ($function != 'func4') return false;
		echo "<p>MyClass->MyMethod called for lookup function <strong>" . $function . "</strong></p>";
		return './functions/' . $function . '.php';
	}
}



// Ok, let's go !

require_once '../class.Lazy.php';

var_dump (Lazy::functions ());
echo '<hr />';

Lazy::register ('MyFunction');
Lazy::call ('func1', 'param1', 'param2');
Lazy::unregister ('MyFunction');

var_dump (Lazy::functions ());
echo '<hr />';

Lazy::register ($MyAnonymFunction);
Lazy::call ('func2', 'param1', 'param2');
Lazy::unregister ($MyAnonymFunction);

var_dump (Lazy::functions ());
echo '<hr />';

Lazy::register (array ('MyStaticClass', 'MyStaticMethod'));
Lazy::call ('func3', 'param1', 'param2');
Lazy::unregister (array ('MyStaticClass', 'MyStaticMethod'));

var_dump (Lazy::functions ());
echo '<hr />';

$MyClass = new MyClass;
Lazy::register (array (&$MyClass, 'MyMethod'));
Lazy::call ('func4', 'param1', 'param2');
Lazy::unregister (array ($MyClass, 'MyMethod'));

var_dump (Lazy::functions ());
echo '<hr />';